package com.taotao.springbootApi.controller;

import com.taotao.springbootApi.exception.BusinessException;
import com.taotao.springbootApi.exception.SystemException;
import com.taotao.springbootApi.result.Code;
import com.taotao.springbootApi.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler(SystemException.class)
    public Result doException(SystemException ex){
        //记录日志
        //发消息给运维
        //发邮件给开发者
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    @ExceptionHandler(BusinessException.class)
    public Result doException(BusinessException ex){
        return new Result(ex.getCode(),null,ex.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex){
        return new Result(Code.SYSTEM_UNKNOW_EXCEPTION,null,"异常处理，哪里有异常？不知道！");
    }
}
